import { BusinessStatus } from "~/src/enum/common";
import { useClipboard,usePermission } from "@vueuse/core";

const { copy, isSupported } = useClipboard();

export function isBusinessYse(val:string|any):boolean{
	return val == BusinessStatus.Yse;
}


/** 设置对象数据 */
export function objectAssign<T extends Record<string, any>>(target: T, source: Partial<T>) {
  Object.assign(target, source);
}

/**
 * 重置对象属性
 * @param target 目标对象
 * @param def 默认属性
 * @returns 重置后的对象
 */
export function resetObject<T>(target:T,def?:T):T{
  const value  = def||{}
	//@ts-ignore
  Object.keys(target).forEach((key:string)=>{
		//@ts-ignore
     target[key] = value[key] || null;
  })
  return target;
}

export function obj2any(arr:any[]|undefined):any[]|undefined{
	if(!arr){
		return undefined;
	}
	return arr;
}

export function handleCopy(str:string,showStr:boolean = true){
	const permissionWrite = usePermission('clipboard-write')
	if (!isSupported) {
    window.$message!.error("您的浏览器不支持Clipboard API");
    return;
  }
	if(permissionWrite.value == 'denied'){
    window.$message!.error("拷贝权限被拒绝！");
    return;
	}

  copy(str);
	if(showStr){
		window.$message!.success(`复制成功：${str}`);
	}else{
		window.$message!.success('复制成功');
	}

}
